package aiyh.utils.mapUtil;

import java.util.HashMap;
import java.util.Map;

/**
 * @author EBU7-dev1-ayh
 * @date 2021/8/19 0019 19:45
 * utilMap
 */


public class UtilHashMap<K, V> extends HashMap<K, V> implements Map<K, V> {
	public UtilHashMap(){
		super();
	}
	public UtilHashMap<K,V> uPut(K key, V value) {
		this.put(key,value);
		return this;
	}


	public UtilHashMap<K,V> uPutAll(Map<? extends K, ? extends V> m) {
		super.putAll(m);
		return this;
	}

	public UtilHashMap<K,V> uReplace(K key, V value) {
		super.replace(key, value);
		return this;
	}

	public UtilHashMap<K,V> filter(UtilMapFilter<? super K, ? super V> predicate){
		UtilHashMap<K,V> newMap = new UtilHashMap<>();
		for (Entry<K,V> entry : this.entrySet()){
			if(predicate.test(entry.getKey(), entry.getValue())){
				newMap.put(entry.getKey(),entry.getValue());
			}
		}
		return newMap;
	}
}
